﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using FluentValidation;

namespace StringVariables
{
    public class VariableDefinitionValidator: AbstractValidator<VariableDefinition>
    {
        public VariableDefinitionValidator()
        {
            RuleFor(i => i.Name).NotEmpty();
            RuleFor(i => i.Type).NotNull();
            RuleFor(i => i.DefaultValue).Must((i, d) => 
                string.IsNullOrWhiteSpace(d) || (i.Type != null && i.Type.IsValid(d)));
        }
    }
}
